package com.zelin.search.config;

import lombok.Data;
import org.apache.http.HttpHost;
import org.elasticsearch.client.RestClient;
import org.elasticsearch.client.RestHighLevelClient;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * 描述: ES的配置
 * 作者: WF
 * 创建时间: 2021/7/20 15:20
 */
@ConfigurationProperties(prefix = "elasticsearch")
@Configuration                  //相当于：applicationContext.xml
@Data
public class ElasticSearchConfig {
    private String host ;
    private Integer port ;

    @Bean                       //相当于：<bean>标签
    public RestHighLevelClient highLevelClient(){
        return new RestHighLevelClient(
                RestClient.builder(new HttpHost(host, port, "http")));
    }
}
